package jircbot.irc;

/**
 * TODO: Add a flag that show the Irc object has connected and/or registerded
 * 
 * @author matt
 */
public class IrcServerMessage {
	
	private IrcUser user;
	
	private String command;
	private String message;
	private String target;
	private String data;

	IrcServerMessage(String serverDataLine)
	{
		if (serverDataLine.startsWith("PING"))
		{
			setCommand("PING");
			setData(serverDataLine.substring(6));
		}

		if (serverDataLine.split(":")[1].contains("!"))
		{
			user = new IrcUser(serverDataLine.substring(1,serverDataLine.indexOf(" ")));
			
			//TODO: Sort IP out
			setDestination(serverDataLine.split(" ")[2]);
			setCommand(serverDataLine.split(" ")[1]);

			if (serverDataLine.split(":", 3).length > 2)
			{
				setMessage(serverDataLine.split(":", 3)[2]);
			}

			if (getCommand().equals("MODE"))
			{
				setData(serverDataLine.split(" ", 4)[3]);
			}
		}
	}

	public IrcUser getUser()
	{
		return user;
	}

	public String getCommand()
	{
		return command;
	}
	
	public String getMessage()
	{
		return message;
	}

	public String getData()
	{
		return data;
	}

	public String getTarget()
	{
		return target;
	}

	private void setData(String data)
	{
		this.data = data;
	}

	private void setMessage(String message)
	{
		this.message = message;
	}

	private void setDestination(String target)
	{
		this.target = target;
	}

	private void setCommand(String command)
	{
		this.command = command;
	}
}